﻿using System;
using System.Globalization;

namespace CodeTitans.Core
{
    /// <summary>
    /// Class that stores info about given range.
    /// </summary>
    public class Range
    {
        private readonly Int32 _location;
        private readonly Int32 _length;

        /// <summary>
        /// Gets the starting from zero and with zero length range.
        /// </summary>
        public static readonly Range Zero = new Range(0, 0);

        /// <summary>
        /// Init constructor.
        /// </summary>
        public Range(Int32 location, Int32 length)
        {
            _location = location;
            _length = length;
        }

        #region Properties

        /// <summary>
        /// Gets the start location of the range.
        /// </summary>
        public Int32 Location
        {
            get { return _location; }
        }

        /// <summary>
        /// Gets the length of the range.
        /// </summary>
        public Int32 Length
        {
            get { return _length; }
        }

        #endregion

        /// <summary>
        /// Checks if given value belongs to the range.
        /// </summary>
        public bool Contains(Int32 value)
        {
            return value >= _location && value <= _location + _length;
        }

        /// <summary>
        /// Gets the string representation of the object.
        /// </summary>
        public override string ToString()
        {
            return string.Format(CultureInfo.InvariantCulture, "{0}:{1}", _location, _length);
        }
    }
}
